/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gpaltan.db;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 *
 * @author srkrishnan
 */
public class DBManager {

    private  Connection conn = null;

    public void connectDB(DBInfo dbinfo) {
        
            String url = "jdbc:mysql://"+dbinfo.getHostname()+":"+dbinfo.getPort()+"/";
            String dbName = dbinfo.getDbname();
            String driver = "com.mysql.jdbc.Driver";
            String userName = dbinfo.getUsername();
            String password = dbinfo.getPassword();
            try {
                Class.forName(driver).newInstance();
                conn = DriverManager.getConnection(url + dbName + "?autoreconnect=true", userName, password);
                System.out.println("Connected to the database " + url + dbName);
            } catch (Exception e) {
                dbinfo.setErrormsg(e.getMessage());
                e.printStackTrace();
            }
        
    }

    public  Connection getConnection() {
        return conn;
    }
}